import static org.junit.Assert.*;

import org.junit.Test;

import typistcal.commandlogic.TimeUtility;
import typistcal.exception.WrongTimeFormatException;

//@author A0096911Y
public class TimeTest {
	@Test
	public void testToday() {
		
		// test for the only partition
		String today = TimeUtility.getToday();
		
		assertEquals("17 April 2014", today);

	}
	
	@Test
	public void testTomorrow() {
		
		// test for only partition
		String tomorrow = TimeUtility.getTomorrow();
		
		assertEquals("18 April 2014", tomorrow);
	}
	
	@Test
	public void testRoll() {
		
		String date;
		
		// testing of multiple inputs
		date = TimeUtility.getDateOfDayFromToday(3, true);
		assertEquals("20 April 2014", date);
		
		date = TimeUtility.getDateOfDayFromToday(7, true);
		assertEquals("24 April 2014", date);
		
		date = TimeUtility.getDateOfDayFromToday(2, false);
		assertEquals("15 April 2014", date);
	}
	
	@Test
	public void testParseDate() {
		
		//@skeleton
/*		date = TimeUtility.parseDate("2/26");
		assertEquals("26 February 2015", date);
 * 
 */
		String date;
		
		try {
			// testing of different inputs that the method is supposed to take
			date = TimeUtility.parseDate("2/26");
			assertEquals("26 February 2015", date);
			
//			date = TimeUtility.parseDate("2.29");
//			assertEquals(null, date);
			
			date = TimeUtility.parseDate("4.2");
			assertEquals("2 April 2015", date);
			
			date = TimeUtility.parseDate("4.29");
			assertEquals("29 April 2014", date);
			
			date = TimeUtility.parseDate("today");
			assertEquals("17 April 2014", date);
			
			date = TimeUtility.parseDate("tomorrow");
			assertEquals("18 April 2014", date);
			
			date = TimeUtility.parseDate("tue");
			assertEquals("22 April 2014", date);
			
			date = TimeUtility.parseDate("monday");
			assertEquals("21 April 2014", date);
			
			date = TimeUtility.parseDate("29 mar");
			assertEquals("29 March 2015", date);
			
			date = TimeUtility.parseDate("march 29");
			assertEquals("29 March 2015", date);
			
			date = TimeUtility.parseDate("26/2/2015");
			assertEquals("26 February 2015", date);
			
			date = TimeUtility.parseDate("26/2/2014");
			assertEquals("26 February 2014", date);
			
			date = TimeUtility.parseDate("2 feb 2014");
			assertEquals("2 February 2014", date);
			
			date = TimeUtility.parseDate("this friday");
			assertEquals("18 April 2014", date);
			
			date = TimeUtility.parseDate("this sun");
			assertEquals("20 April 2014", date);
			
			date = TimeUtility.parseDate("next mon");
			assertEquals("21 April 2014", date);
			
		} catch (WrongTimeFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void testParseTime() {
		
		//@skeleton
/*		time = TimeUtility.parseTime("3.45");
		assertEquals("3:45", time);
 * 
 */
		String time;
		
		try {
			// testing of multiple inputs that the method is supposed to take
			// failure cases cannot be tested here because the method will throw an exception...
			time = TimeUtility.parseTime("3.45");
			assertEquals("3:45", time);
			
			time = TimeUtility.parseTime("3.45pm");
			assertEquals("15:45", time);
			
			time = TimeUtility.parseTime("12.45am");
			assertEquals("00:45", time);
			
			time = TimeUtility.parseTime("00.00");
			assertEquals("00:00", time);
			
			
			time = TimeUtility.parseTime("24.00");
			assertEquals("24:00", time);
			
			
		} catch (WrongTimeFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// testing failure testcases
		try {
			time = TimeUtility.parseTime("00.00am");
			assertEquals(true, false);
		} catch (WrongTimeFormatException e) {
			assertEquals(true, true);
		}
		
		try {
			time = TimeUtility.parseTime("25.00");
			assertEquals(true, false);
		} catch (WrongTimeFormatException e) {
			assertEquals(true, true);
		}
	}

	@Test
	public void testIsValidSchedule() {
		
		assertTrue(TimeUtility.isValidSchedule("2 March 2014", "23:59", "3 March 2014", "00:00"));
		assertFalse(TimeUtility.isValidSchedule("3 March 2014", "23:59", "3 March 2014", "00:00"));
		assertTrue(TimeUtility.isValidSchedule("1 March 2014", "23:59", "31 March 2014", "00:00"));
		assertFalse(TimeUtility.isValidSchedule("2 March 2014", "23:59", "2 March 2014", "23:59"));
	}
	
	@Test
	public void testIsDate() {
		
		assertTrue(TimeUtility.isDate("2 mar 2013"));
		assertTrue(TimeUtility.isDate("2 march"));
		assertFalse(TimeUtility.isDate("30 feb 2000"));
		assertTrue(TimeUtility.isDate("today"));
		assertTrue(TimeUtility.isDate("tml"));
		assertTrue(TimeUtility.isDate("4.13"));
		assertTrue(TimeUtility.isDate("13-4-2015"));
		assertTrue(TimeUtility.isDate("29 feb 2004"));
		assertFalse(TimeUtility.isDate("3"));
		
		assertTrue(TimeUtility.isDate("monday"));
		assertTrue(TimeUtility.isDate("next sunday"));
		assertTrue(TimeUtility.isDate("this tue"));
	}
}
